<template>
  <div class="backDiv">
    <el-card style="width: 70%;margin-top: 30px;">
      <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-bottom: 30px;">
        <el-breadcrumb-item :to="{ path: '/header' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>{{this.queryInfo.query}}</el-breadcrumb-item>
      </el-breadcrumb>
      <el-table
        :data="goodslist"
        style="width: 100%"
        border
        stripe>
        <!-- 添加索引列 直接把type属性设置成index即可-->
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="gdName" label="商品名称"></el-table-column>
        <el-table-column prop="gdPrice" label="商品价格"></el-table-column>
        <el-table-column prop="gdCount" label="商品数量"></el-table-column>
        <el-table-column prop="gdIntroduce" label="商品介绍"></el-table-column>
        <el-table-column prop="cateId" label="商品类别"></el-table-column>
        <el-table-column prop="depId" label="商品分区"></el-table-column>
      </el-table>
      <!--      分页区域-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        style="margin-top: 20px">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'GoosList',
  data () {
    return {
      goodslist: [],
      total: 0,
      queryInfo: {}
    }
  },
  created () {
    this.getGoodsList()
  },
  methods: {
    getGoodsList () {
      this.goodslist = this.$route.params.list
      this.total = this.$route.params.total
      this.queryInfo = this.$route.params.queryInfo
      console.log('adsfvbkads')
      console.log(this.goodslist)
    },
    // 监听每页显示数量变化函数
    handleSizeChange (newSize) {
      console.log(newSize)
      this.queryInfo.pagesize = newSize
      // 每页显示数量变化后 重新请求用户列表
      this.getGoods()
    },
    // 监听当前页码变化函数
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getGoods()
    },
    getGoods () {
      this.$axios.get('goods', {params: this.queryInfo})
        .then(resp => {
          if (resp && resp.data.status !== 200) {
            return this.$message.error('获取商品列表失败!')
          }
          this.goodslist = resp.data.data.data
          this.total = resp.data.data.totalpage
          console.log('test1')
          console.log(resp.data.data)
          this.$message.success('获取商品列表成功!')
        })
    }
  }
}
</script>

<style scoped>
.backDiv {
  width: 100%;
  background-repeat: repeat;
  display: flex;
  justify-content: center;
  align-items:center;
  flex-flow: column;
}
</style>
